X-Git-Url: https://git.r.bdr.sh/rbdr/super-polarity/blobdiff_plain/8534e46e400268c5ceffb3b14f02cef39eedae8f..3de51c6f55d304f038df1b77c8ab346e2a187fe1:/Super%20Polarity/BasicGenerator.cs diff --git a/Super Polarity/BasicGenerator.cs b/Super Polarity/BasicGenerator.cs new file mode 100644 index 0000000..ba51742 --- /dev/null +++ b/Super Polarity/BasicGenerator.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.Xna.Framework; + +namespace SuperPolarity +{ + class BasicGenerator + { + public enum Ships : byte { Ship, Scout, Battlecruiser }; + + protected Ships ShipType; + protected SuperPolarity Game; + protected int ScoreThreshold; + protected int Rate; + protected int CurrentTime; + protected Random Randomizer; + protected Vector2 Position; + + public void Initialize(SuperPolarity game, Vector2 position, Ships shipType, int rate, int scoreThreshold) + { + Game = game; + ShipType = shipType; + ScoreThreshold = scoreThreshold; + Rate = rate; + Randomizer = new Random(); + Position = position; + CurrentTime = rate; + } + + public void Update(GameTime gameTime) + { + if (ActorManager.CountBaddies() > 50) + { + return; + } + + if (Game.Player.Score >= ScoreThreshold) + { + CurrentTime = CurrentTime + gameTime.ElapsedGameTime.Milliseconds; + + if (CurrentTime >= Rate) + { + CurrentTime = 0; + Spawn(); + } + } + } + + protected void Spawn() + { + var polarity = Ship.Polarity.Positive; + + if (Randomizer.Next(2) == 1) + { + polarity = Ship.Polarity.Negative; + } + + if (ShipType == Ships.Ship) + { + Renderer.CheckIn(ActorFactory.CreateShip(polarity, Position)); + } + + if (ShipType == Ships.Scout) + { + Renderer.CheckIn(ActorFactory.CreateScout(polarity, Position)); + } + + if (ShipType == Ships.Battlecruiser) + { + Renderer.CheckIn(ActorFactory.CreateCruiser(polarity, Position)); + } + + } + } +}